<template>
  <div class="container flow-column h100">
    <div class="container-main h100">
      <list-table-new v-bind="tableSetting" ref="tableRef"></list-table-new>
    </div>
  </div>
</template>
<script>
import { getWorkTicketList } from "@/api/twoTicketManagement/workTicket.js";
export default {
  data() {
    return {
      tableSetting: {
        singleRow: true,
        radioShow: true,
        showFilterBtn: false, // 显示过滤器
        showCustomBtn: false, // 显示自定义列
        // 搜索框
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15,
          },
          searchArr: [
            {
              type: "select",
              label: "工作票类型",
              model: "type",
              option: this.$store.getters["dirtData"]("ticket_work_type"),
            },
            {
              type: "organization",
              label: "开票单位",
              model: "unitName",
              idsStr: "unit",
              placeholder: "请选择或输入",
            },
            {
              type: "input",
              label: "标题",
              model: "title",
              placeholder: "请输入",
            },
            {
              type: "select",
              label: "状态",
              model: "statusList",
              multiple: true,
              option: this.$store.getters["dirtData"]("ticket_work_status"),
            },
            {
              type: "datetimerange",
              label: "计划起止时间",
              model: "estimatedTime",
            },
            {
              type: "location",
              label: "工作地点",
              model: "locationName",
              idsStr: "location",
              placeholder: "请选择或输入",
            },
            {
              type: "input",
              label: "工作票票号",
              model: "code",
              placeholder: "请输入",
            },
            {
              type: "select",
              label: "是否外单位",
              model: "externalFlag",
              option: [
                { label: "是", value: 1 },
                { label: "否", value: 0 },
              ],
            },
            {
              type: "organization",
              label: "工作班组",
              model: "team",
              placeholder: "请选择或输入",
            },
            {
              type: "userOnly",
              label: "工作负责人",
              model: "directorName",
              placeholder: "请选择或输入",
            },
            {
              type: "datetimerange",
              label: "填票时间",
              model: "createTime",
            },
          ],
        },
        // 表头
        column: [
          {
            label: "状态",
            prop: "status",
            formatter: (row) => {
              let types = this.$store.getters["dirtData"]("ticket_work_status");
              let val = row.status;
              let obj = types.find((i) => i.value == val);
              return obj ? obj.label : val;
            },
          },
          {
            label: "工作票类型",
            prop: "type",
            formatter: (row) => {
              let types = this.$store.getters["dirtData"]("ticket_work_type");
              let val = row.type;
              let obj = types.find((i) => i.value == val);
              return obj ? obj.label : val;
            },
          },
          {
            label: "工作票票号",
            prop: "code",
          },
          {
            label: "标题",
            prop: "title",
          },
          {
            label: "开票单位",
            prop: "unitName",
          },
          {
            label: "工作负责人",
            prop: "directorName",
          },
          {
            label: "工作班组",
            prop: "team",
          },

          {
            label: "工作地点",
            prop: "locationName",
          },

          {
            label: "计划开始时间",
            prop: "estimatedStartTime",
          },
          {
            label: "计划结束时间",
            prop: "estimatedEndTime",
          },
        ],
        // 表格方法
        tableMethods: {
          //点击行的方法
          rowClick: async (val) => {
            this.$refs.tableRef.radioSelect(val);
          },
        },
      },
    };
  },
  created() {
    let query = {
      // statusList: ["1", "2", "3", "4", "5", "6", "7"],
      // unit:
      //   this.$store.state.user.userInfo.orgId ||
      //   this.$store.state.user.userInfo.deptId,
      // unitName:
      //   this.$store.state.user.userInfo.orgName ||
      //   this.$store.state.user.userInfo.deptName,
    };
    this.tableSetting.searchObj.queryData = Object.assign(
      this.tableSetting.searchObj.queryData,
      query
    );
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.$refs.tableRef.searchData();
    },
    // 查询表格数据
    async getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      // if (sortStr.length > 0) {
      //   queryData.orders = sortStr;
      // }
      if (queryData.estimatedTime) {
        queryData.estimatedStartTime = queryData.estimatedTime[0];
        queryData.estimatedEndTime = queryData.estimatedTime[1];
        delete queryData.estimatedTime;
      }
      if (queryData.createTime) {
        queryData.startCreateTime = queryData.createTime[0];
        queryData.endCreateTime = queryData.createTime[1];
        delete queryData.createTime;
      }
      getWorkTicketList(queryData)
        .then((list) => {
          this.$set(this.tableSetting, "tableData", list.data.list);
          this.$set(this.tableSetting, "totalNumber", list.data.total);
        })
        .catch((e) => {
          this.$set(this.tableSetting, "tableData", []);
          this.$set(this.tableSetting, "totalNumber", 0);
        });
    },
    // 返回选中数据
    getSelectData() {
      let val = this.$refs.tableRef.getRadioData();
      let selectData = val ? { id: val.id, type: val.type } : null;
      return selectData;
    },
  },
};
</script>
<style lang="less" scoped>
.flow-column {
  display: flex;
  flex-flow: column nowrap;
}
</style>